import axios from "axios";
import Cookies from "js-cookie";

export function request(config) {
    const instance = axios.create({
        baseURL: 'https://localhost:7106/api',
        //baseURL: 'https://localhost:7153/api',
        timeout: 1000,
    });
    console.log(11);
    // 添加请求拦截�?
    instance.interceptors.request.use(function (config) {
        // 在发送请求之前做些什�?
        let token = Cookies.get('token');
        if (token) {
            config.headers['Authorization'] = token;
        }
        return config;
    }, function (error) {
        // 对请求错误做些什�?
        return Promise.reject(error);
    });

    // 添加响应拦截
    instance.interceptors.response.use(function (response) {
        // 对响应数据做点什
        // 如果是没有状态码的响应
        console.log('response' + response);
        if (!response.data.code) {
            const resType = Object.prototype.toString.call(response.data);
            const isBlob = resType === '[object Blob]';
            if (isBlob || resType === '[object String]') return response;
        }
        return response.data;
    }, function (error) {
        // 对响应错误做点什�?
        return Promise.reject(error);
    });
    //返回
    return instance(config);
}



